/**
 * 游戏数据定义
 * 包含怪物、物品、技能等游戏数据的定义
 */

import { COLORS, RARITY_TYPES, ITEM_TYPES } from './constants.js';

// 怪物数据定义
export const MONSTER_DATA = {
    SLIME: {
        name: '史莱姆',
        health: 50,
        damage: 5,
        exp: 20,
        color: COLORS.MONSTER_SLIME,
        dropRate: 0.8,
        level: 1,
        speed: 0.8,
        description: '最基础的怪物，适合新手练习'
    },
    SKELETON: {
        name: '骷髅战士',
        health: 80,
        damage: 8,
        exp: 35,
        color: COLORS.MONSTER_SKELETON,
        dropRate: 0.85,
        level: 2,
        speed: 1.0,
        description: '不死族战士，拥有基本的战斗技能'
    },
    ORC: {
        name: '兽人战士',
        health: 120,
        damage: 12,
        exp: 50,
        color: COLORS.MONSTER_ORC,
        dropRate: 0.9,
        level: 3,
        speed: 0.9,
        description: '强壮的兽人战士，攻击力较高'
    },
    DRAGON: {
        name: '幼龙',
        health: 200,
        damage: 25,
        exp: 100,
        color: COLORS.MONSTER_DRAGON,
        dropRate: 0.95,
        level: 5,
        speed: 1.2,
        description: '强大的龙族，拥有火焰攻击'
    },
    PHOENIX: {
        name: '火凤凰',
        health: 300,
        damage: 35,
        exp: 150,
        color: COLORS.MONSTER_PHOENIX,
        dropRate: 1.0,
        level: 7,
        speed: 1.5,
        description: '传说中的火鸟，极其危险'
    }
};

// 装备数据定义
export const EQUIPMENT_DATA = {
    // 武器
    WEAPONS: {
        WOODEN_SWORD: {
            name: '木剑',
            type: ITEM_TYPES.WEAPON,
            damage: 5,
            rarity: RARITY_TYPES.COMMON,
            color: '#8B4513',
            level: 1,
            description: '最基础的武器，由木材制成'
        },
        IRON_SWORD: {
            name: '铁剑',
            type: ITEM_TYPES.WEAPON,
            damage: 15,
            rarity: RARITY_TYPES.UNCOMMON,
            color: '#C0C0C0',
            level: 3,
            description: '坚固的铁制剑，攻击力不错'
        },
        STEEL_SWORD: {
            name: '精钢剑',
            type: ITEM_TYPES.WEAPON,
            damage: 25,
            rarity: RARITY_TYPES.RARE,
            color: '#B0C4DE',
            level: 5,
            description: '精工锻造的钢剑，锋利无比'
        },
        MAGIC_SWORD: {
            name: '魔法剑',
            type: ITEM_TYPES.WEAPON,
            damage: 35,
            rarity: RARITY_TYPES.EPIC,
            color: '#9370DB',
            level: 7,
            description: '蕴含魔力的神秘之剑'
        },
        LEGENDARY_SWORD: {
            name: '传说之剑',
            type: ITEM_TYPES.WEAPON,
            damage: 50,
            rarity: RARITY_TYPES.LEGENDARY,
            color: '#FFD700',
            level: 10,
            description: '传说中的神器，拥有无穷力量'
        }
    },
    
    // 护甲
    ARMOR: {
        LEATHER_ARMOR: {
            name: '皮甲',
            type: ITEM_TYPES.ARMOR,
            defense: 5,
            health: 20,
            rarity: RARITY_TYPES.COMMON,
            color: '#8B4513',
            level: 1,
            description: '轻便的皮制护甲'
        },
        IRON_ARMOR: {
            name: '铁甲',
            type: ITEM_TYPES.ARMOR,
            defense: 15,
            health: 40,
            rarity: RARITY_TYPES.UNCOMMON,
            color: '#C0C0C0',
            level: 3,
            description: '坚固的铁制护甲'
        },
        STEEL_ARMOR: {
            name: '精钢甲',
            type: ITEM_TYPES.ARMOR,
            defense: 25,
            health: 60,
            rarity: RARITY_TYPES.RARE,
            color: '#4682B4',
            level: 5,
            description: '精工打造的钢制护甲'
        },
        MAGIC_ARMOR: {
            name: '魔法甲',
            type: ITEM_TYPES.ARMOR,
            defense: 35,
            health: 80,
            rarity: RARITY_TYPES.EPIC,
            color: '#9370DB',
            level: 7,
            description: '蕴含魔力的神秘护甲'
        },
        LEGENDARY_ARMOR: {
            name: '传说护甲',
            type: ITEM_TYPES.ARMOR,
            defense: 50,
            health: 120,
            rarity: RARITY_TYPES.LEGENDARY,
            color: '#FFD700',
            level: 10,
            description: '传说中的神级护甲'
        }
    },
    
    // 饰品
    ACCESSORIES: {
        STRENGTH_RING: {
            name: '力量戒指',
            type: ITEM_TYPES.ACCESSORY,
            damage: 10,
            rarity: RARITY_TYPES.UNCOMMON,
            color: '#FFD700',
            level: 2,
            description: '增强力量的魔法戒指'
        },
        DEFENSE_RING: {
            name: '守护戒指',
            type: ITEM_TYPES.ACCESSORY,
            defense: 10,
            rarity: RARITY_TYPES.UNCOMMON,
            color: '#00CED1',
            level: 2,
            description: '提供保护的魔法戒指'
        },
        HEALTH_RING: {
            name: '生命戒指',
            type: ITEM_TYPES.ACCESSORY,
            health: 50,
            rarity: RARITY_TYPES.RARE,
            color: '#FF69B4',
            level: 3,
            description: '增加生命力的珍贵戒指'
        },
        SPEED_RING: {
            name: '敏捷戒指',
            type: ITEM_TYPES.ACCESSORY,
            speed: 1,
            rarity: RARITY_TYPES.RARE,
            color: '#00FF00',
            level: 4,
            description: '提升移动速度的稀有戒指'
        },
        GUARDIAN_NECKLACE: {
            name: '守护项链',
            type: ITEM_TYPES.ACCESSORY,
            defense: 5,
            health: 25,
            rarity: RARITY_TYPES.RARE,
            color: '#00CED1',
            level: 4,
            description: '全面提升防护的项链'
        }
    }
};

// 消耗品数据定义
export const CONSUMABLE_DATA = {
    HEALTH_POTION: {
        name: '生命药水',
        type: ITEM_TYPES.POTION,
        healing: 50,
        rarity: RARITY_TYPES.COMMON,
        color: '#FF0000',
        description: '恢复少量生命值'
    },
    GREATER_HEALTH_POTION: {
        name: '大生命药水',
        type: ITEM_TYPES.POTION,
        healing: 100,
        rarity: RARITY_TYPES.UNCOMMON,
        color: '#DC143C',
        description: '恢复大量生命值'
    },
    SUPER_HEALTH_POTION: {
        name: '超级生命药水',
        type: ITEM_TYPES.POTION,
        healing: 200,
        rarity: RARITY_TYPES.RARE,
        color: '#8B0000',
        description: '恢复超大量生命值'
    },
    MANA_POTION: {
        name: '魔法药水',
        type: ITEM_TYPES.POTION,
        manaRestore: 50,
        rarity: RARITY_TYPES.COMMON,
        color: '#0000FF',
        description: '恢复少量魔法值'
    },
    GREATER_MANA_POTION: {
        name: '大魔法药水',
        type: ITEM_TYPES.POTION,
        manaRestore: 100,
        rarity: RARITY_TYPES.UNCOMMON,
        color: '#4169E1',
        description: '恢复大量魔法值'
    }
};

// 技能数据定义
export const SKILL_DATA = {
    heal: {
        name: '治疗术',
        damage: 0,
        healing: 30,
        mana: 15,
        maxCooldown: 120,
        cooldown: 0,
        icon: '💚',
        description: '恢复自身生命值',
        type: 'healing',
        level: 1
    },
    fireball: {
        name: '火球术',
        damage: 25,
        healing: 0,
        mana: 20,
        maxCooldown: 60,
        cooldown: 0,
        icon: '🔥',
        description: '发射火球攻击敌人',
        type: 'damage',
        level: 1
    },
    lightning: {
        name: '闪电术',
        damage: 35,
        healing: 0,
        mana: 25,
        maxCooldown: 90,
        cooldown: 0,
        icon: '⚡',
        description: '召唤闪电攻击敌人',
        type: 'damage',
        level: 2
    },
    ice_shard: {
        name: '冰锥术',
        damage: 30,
        healing: 0,
        mana: 22,
        maxCooldown: 75,
        cooldown: 0,
        icon: '❄️',
        description: '发射冰锥攻击并减速敌人',
        type: 'damage',
        level: 3
    },
    meteor: {
        name: '流星术',
        damage: 50,
        healing: 0,
        mana: 40,
        maxCooldown: 180,
        cooldown: 0,
        icon: '☄️',
        description: '召唤流星造成大范围伤害',
        type: 'damage',
        level: 5
    }
};

// 地图数据定义（从map-manager.js中提取并优化）
export const MAP_DATA = {
    forest_1: {
        id: 'forest_1',
        name: '新手森林',
        level: 1,
        description: '适合新手冒险者的安全森林',
        size: { width: 40, height: 40 },
        monsterTypes: ['SLIME', 'SKELETON'],
        monsterLevelRange: [1, 3],
        monsterCount: 8,
        spawnRate: 0.008,
        itemDropRate: 0.6,
        background: '#2d5016',
        difficulty: 'easy',
        tileTypes: {
            grass: { color: COLORS.MAP_GRASS, walkable: true },
            tree: { color: COLORS.MAP_TREE, walkable: false },
            water: { color: COLORS.MAP_WATER, walkable: false },
            rock: { color: COLORS.MAP_ROCK, walkable: false }
        },
        portals: [
            { x: 5, y: 5, targetMap: 'cave_1', name: '神秘洞穴入口' },
            { x: 35, y: 35, targetMap: 'forest_2', name: '深入森林' }
        ]
    },
    forest_2: {
        id: 'forest_2',
        name: '森林深处',
        level: 2,
        description: '更危险的森林深处，怪物更强',
        size: { width: 50, height: 50 },
        monsterTypes: ['SKELETON', 'ORC'],
        monsterLevelRange: [3, 6],
        monsterCount: 12,
        spawnRate: 0.01,
        itemDropRate: 0.7,
        background: '#1a3d0a',
        difficulty: 'medium',
        tileTypes: {
            grass: { color: '#388E3C', walkable: true },
            tree: { color: '#1B5E20', walkable: false },
            water: { color: '#1976D2', walkable: false },
            rock: { color: '#5D4037', walkable: false },
            swamp: { color: '#4A148C', walkable: true }
        },
        portals: [
            { x: 5, y: 5, targetMap: 'forest_1', name: '返回新手森林' },
            { x: 45, y: 45, targetMap: 'mountain_1', name: '前往山脉' }
        ]
    },
    cave_1: {
        id: 'cave_1',
        name: '神秘洞穴',
        level: 2,
        description: '黑暗的洞穴，充满未知的危险',
        size: { width: 35, height: 35 },
        monsterTypes: ['SKELETON', 'ORC'],
        monsterLevelRange: [4, 7],
        monsterCount: 10,
        spawnRate: 0.012,
        itemDropRate: 0.8,
        background: '#1a1a1a',
        difficulty: 'medium',
        tileTypes: {
            stone: { color: '#424242', walkable: true },
            wall: { color: '#212121', walkable: false },
            crystal: { color: '#9C27B0', walkable: false },
            lava: { color: '#FF5722', walkable: false }
        },
        portals: [
            { x: 5, y: 5, targetMap: 'forest_1', name: '返回森林' },
            { x: 30, y: 30, targetMap: 'cave_2', name: '深入洞穴' }
        ]
    },
    cave_2: {
        id: 'cave_2',
        name: '洞穴深处',
        level: 3,
        description: '洞穴的最深处，极其危险',
        size: { width: 30, height: 30 },
        monsterTypes: ['ORC', 'DRAGON'],
        monsterLevelRange: [6, 10],
        monsterCount: 8,
        spawnRate: 0.015,
        itemDropRate: 0.9,
        background: '#0d0d0d',
        difficulty: 'hard',
        tileTypes: {
            stone: { color: '#616161', walkable: true },
            wall: { color: '#424242', walkable: false },
            crystal: { color: '#E91E63', walkable: false },
            lava: { color: '#FF9800', walkable: false },
            treasure: { color: '#FFD700', walkable: true }
        },
        portals: [
            { x: 5, y: 5, targetMap: 'cave_1', name: '返回上层洞穴' }
        ]
    },
    mountain_1: {
        id: 'mountain_1',
        name: '险峻山脉',
        level: 3,
        description: '高耸的山脉，强大的怪物栖息地',
        size: { width: 45, height: 45 },
        monsterTypes: ['ORC', 'DRAGON'],
        monsterLevelRange: [5, 9],
        monsterCount: 10,
        spawnRate: 0.012,
        itemDropRate: 0.85,
        background: '#3e2723',
        difficulty: 'hard',
        tileTypes: {
            rock: { color: '#8D6E63', walkable: true },
            mountain: { color: '#5D4037', walkable: false },
            snow: { color: '#ECEFF1', walkable: true },
            ice: { color: '#B3E5FC', walkable: false },
            peak: { color: '#FFEB3B', walkable: true }
        },
        portals: [
            { x: 5, y: 5, targetMap: 'forest_2', name: '返回森林' },
            { x: 40, y: 40, targetMap: 'volcano_1', name: '前往火山' }
        ]
    },
    volcano_1: {
        id: 'volcano_1',
        name: '火山口',
        level: 4,
        description: '炽热的火山口，最强大的怪物聚集地',
        size: { width: 40, height: 40 },
        monsterTypes: ['DRAGON', 'PHOENIX'],
        monsterLevelRange: [8, 15],
        monsterCount: 6,
        spawnRate: 0.02,
        itemDropRate: 1.0,
        background: '#bf360c',
        difficulty: 'extreme',
        tileTypes: {
            lava: { color: '#FF5722', walkable: false },
            rock: { color: '#D84315', walkable: true },
            obsidian: { color: '#212121', walkable: false },
            fire: { color: '#FF9800', walkable: false },
            treasure: { color: '#FFD700', walkable: true }
        },
        portals: [
            { x: 5, y: 5, targetMap: 'mountain_1', name: '返回山脉' }
        ]
    }
};

// 合并所有物品数据以便统一访问
export const ALL_ITEMS = {
    ...EQUIPMENT_DATA.WEAPONS,
    ...EQUIPMENT_DATA.ARMOR,
    ...EQUIPMENT_DATA.ACCESSORIES,
    ...CONSUMABLE_DATA
};

// 按类型获取物品的辅助函数
export function getItemsByType(type) {
    switch (type) {
        case ITEM_TYPES.WEAPON:
            return Object.values(EQUIPMENT_DATA.WEAPONS);
        case ITEM_TYPES.ARMOR:
            return Object.values(EQUIPMENT_DATA.ARMOR);
        case ITEM_TYPES.ACCESSORY:
            return Object.values(EQUIPMENT_DATA.ACCESSORIES);
        case ITEM_TYPES.POTION:
        case ITEM_TYPES.CONSUMABLE:
            return Object.values(CONSUMABLE_DATA);
        default:
            return [];
    }
}

// 按稀有度获取物品的辅助函数
export function getItemsByRarity(rarity) {
    return Object.values(ALL_ITEMS).filter(item => item.rarity === rarity);
}

// 按等级获取物品的辅助函数
export function getItemsByLevel(minLevel, maxLevel = Infinity) {
    return Object.values(ALL_ITEMS).filter(item => 
        item.level >= minLevel && item.level <= maxLevel
    );
}

